﻿#ifndef _TianJiaCS_H__
#define _TianJiaCS_H__


#ifdef TianJiaCS_LIBRARY
#define TianJiaCS_API __declspec(dllexport)
#else
#define TianJiaCS_API __declspec(dllimport)
#endif

#include <winsock2.h>
#include <string>
#include <vector>
using namespace std;

// 声明一个服务器响应消息的函数指针类型
// 往 answerMsg 里填的字符串会发送给当前连接的客户端
// 也可以通过 serverSendMsg 函数给别的客户端发消息

typedef int (*SERVER_FUNC)(
        int clientId,
        const string& reqMsg,
        string& answerMsg,
        void* lpParameter);

class TianJiaCS_API TianJiaCS
{
private:

public:

public:
    TianJiaCS();
    ~TianJiaCS();


    int start(int port,
              SERVER_FUNC onReceive,
               SERVER_FUNC onConnected=nullptr,
               SERVER_FUNC onDisconnect=nullptr,
               void* funParam=nullptr);
    void stop(int sid);

    bool sendMsg(int sid, int cid, const string& msg);
    bool sendMsgToAll(int sid, const string& msg);

};




#endif
